package com.fengmi.controller;

import com.fengmi.dto.PageDTO;
import com.fengmi.entity.MallGoodsBrandEntity;
import com.fengmi.service.MallGoodsBrandService;
import com.fengmi.vo.PageResultVO;
import com.fengmi.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("brand")
@CrossOrigin
@Api(tags = "品牌管理控制器")
public class MallGoodsBrandController {
    @Autowired
    private MallGoodsBrandService mallGoodsBrandService;

    @PostMapping("findByPage")
    @ApiOperation("分页条件查询")
    private PageResultVO findByPage(@ApiParam("品牌dto") @RequestBody PageDTO<MallGoodsBrandEntity> pageDTO){
        PageResultVO<MallGoodsBrandEntity> pageResultVo = mallGoodsBrandService.findByPage(pageDTO);
        return pageResultVo;
    }
    @PostMapping("save")
    @ApiOperation("添加品牌")
    public ResultVO save(@RequestBody @ApiParam("品牌实体类") MallGoodsBrandEntity mallGoodsBrand) {
        return mallGoodsBrandService.saveInsert(mallGoodsBrand);
    }

    @GetMapping("findOne/{brandId}")
    @ApiOperation("查询单个品牌")
    public ResultVO findOne(@PathVariable String brandId) {
        return mallGoodsBrandService.findOneBrandById(brandId);
    }

    @GetMapping("toggleStatus/{id}/{showStatus}")
    @ApiOperation("修改品牌展示状态")
    public ResultVO toggleStatus(@PathVariable String id, @PathVariable Integer showStatus) {
        return mallGoodsBrandService.toggleBrandShowStatus(id, showStatus);
    }

    @GetMapping("findAll")
    @ApiOperation("查询所有品牌")
    public ResultVO findAll() {
        return mallGoodsBrandService.selectAllBrand();
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除品牌")
    public ResultVO delBrand(@PathVariable @ApiParam("品牌id") String id) {
        return mallGoodsBrandService.deleteBrandById(id);
    }

    @PutMapping
    @ApiOperation("修改品牌")
    public ResultVO updateBrand(@RequestBody @ApiParam("品牌实体类") MallGoodsBrandEntity mallGoodsBrand) {
        return mallGoodsBrandService.updateBrandInfo(mallGoodsBrand);
    }

    @DeleteMapping("delMore")
    @ApiOperation("批量删除")
    public ResultVO delMore(@RequestBody Integer[] ids) {
        return mallGoodsBrandService.delMoreThanOneBrand(ids);
    }
}
